package structural.proxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibProxy implements MethodInterceptor {

    private Object m_pObj;

    public Object getInstance(Object objTarget) {
        this.m_pObj = objTarget;
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(this.m_pObj.getClass());
        enhancer.setCallback(this);
        return enhancer.create();
    }



    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("热身");
        Object objResult = methodProxy.invoke(this.m_pObj, args);
        System.out.println("拉筋");
        return null;
    }

}
